define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classes/classes/index' + location.search,
                    add_url: 'classes/classes/add',
                    edit_url: 'classes/classes/edit',
                    del_url: 'classes/classes/del',
                    multi_url: 'classes/classes/multi',
                    dragsort_url: '',
                    table: 'classes_classes',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: Config.students_id ? 'Classes.id' : 'id',
                sortName: Config.students_id ? 'Classes.id' : 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'title', title: __('Title')},
                        {field: 'entry_year', title: __('Entry_year')},
                        {field: 'teacher.realname', title: __('Teachersclasses'),operate: false},
                        {field: 'teacher.mobile', title: __('Mobile'),operate: false},
                        {field: 'requireVerify', title: __('requireVerify'),operate: false,formatter: function(value, row, index){
                            return value == 1 ? '需要审核' : '不需要审核';
                        }},
                        {field: 'disable', title: __('状态'),formatter: function(value, row, index){
                                return value == 1 ? '置灰' : '正常';
                            }},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: '查看学生',
                                    text: '查看学生',
                                    extend:'data-area=["90%","90%"]',
                                    classname: 'btn btn-xs btn-primary btn-dialog btncsa',
                                    icon: 'fa fa-list',
                                    url: function (row) {
                                        return 'classes/classesstudent?classes_id=' + row.id
                                    },
                                }
                            ],
                            formatter: Table.api.formatter.operate,
                        }
                    ]
                ],
                search: false,
                commonSearch: true
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});